<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
<#include "/jeecms_sys/head.html"/>
<script type="text/javascript">
$(function() {
	$("#jvForm").validate();
});
</script>
<style type="text/css">
.items{padding-top:1px;}
</style>
</head>
<body>
<div class="box-positon">
	<div class="rpos"><@s.m "global.position"/>: <@s.m "cmsVoteTopic.function"/> - <@s.m "global.add"/></div>
	<form class="ropt">
		<input type="submit" class="return-button" value="<@s.m "global.backToList"/>" onclick="this.form.action='v_list.do';"/>
	</form>
	<div class="clear"></div>
</div>
<div class="body-box">
<@p.form id="jvForm" action="o_save.do">
<@p.text label="cmsVoteTopic.title" name="title" required="true" class="required" style="width:400px" maxlength="255"/>
<@p.textarea label="cmsVoteTopic.description" name="description" rows="3" style="width:400px" maxlength="255"/>
<@p.td label="cmsVoteTopic.time">
<table>
	<tr>
		<td><@s.m "cmsVoteTopic.startTime"/></td>
		<td><input type="text" name="startTime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate"/></td>
		<td rowspan="2" valign="middle"><span class="pn-fhelp"><@s.m "cmsVoteTopic.time.help"/></span></td>
	</tr>
	<tr>
		<td><@s.m "cmsVoteTopic.endTime"/></td>
		<td><input type="text" name="endTime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="Wdate"/></td>
	<tr/>
</table>
</@p.td><@p.tr/>
<@p.text label="cmsVoteTopic.repeateHour" name="repeateHour" class="digits" maxlength="10" help="cmsVoteTopic.repeateHour.help"/>
<@p.radio label="cmsVoteTopic.restrictMember" name="restrictMember" value="false" list={"true":"global.true","false":"global.false"} help="cmsVoteTopic.restrictMember.help"/>
<@p.radio label="cmsVoteTopic.restrictIp" name="restrictIp" value="false" list={"true":"global.true","false":"global.false"}/>
<@p.radio label="cmsVoteTopic.restrictCookie" name="restrictCookie" value="true" list={"true":"global.true","false":"global.false"} help="cmsVoteTopic.restrictCookie.help"/>
<@p.td label="cmsVoteTopic.multiSelect" required="true">
<input type="text" name="multiSelect" value="1" class="required digits" style="width:100px"/>
<label style="padding-left:20px"><input type="checkbox" onclick="$('#def').val(this.checked);"/><@s.m "cmsVoteTopic.def"/><input type="hidden" id="def" name="def" value="false"/></label>
<label style="padding-left:10px"><input type="checkbox" onclick="$('#disabled').val(this.checked);"/><@s.m "cmsVoteTopic.disabled"/><input type="hidden" id="disabled" name="disabled" value="false"/></label>
</@p.td><@p.tr/>
<@p.td>
<div>
	<div class="items"><@s.m "cmsVoteTopic.subTopics"/>&nbsp; <input type="button" class="add_subTopic" value="<@s.m "cmsVoteTopic.addSubTopic"/>" onclick="addSubTopic();"/></div>
	<div id="subTopicContainer">
	</div>
</div>
</@p.td><@p.tr/>
<@p.td><@p.submit code="global.submit" onclick="return checkVoteItem()"/> &nbsp; <@p.reset code="global.reset"/></@p.td>
</@p.form>
</div>

<textarea id="subTopicTpl" style="display:none;">
<div class="items">
<@s.m "cmsVoteItem.title"/>: <input type="text" name="subtitle" id="subtitle{0}" style="width:300px"/>
&nbsp; <@s.m "cmsVoteItem.priority"/>: <input type="text" name="subPriority" value="{0}" style="width:30px"/>
<@s.m "cmsVoteTopic.type"/>: <input type="radio" name="typeId{0}" id="typeId{0}_1" value="1" onclick="changeAddItemButton({0},this.value)" checked="checked"><@s.m "cmsVoteTopic.type.single"/></input><input type="radio" name="typeId{0}" id="typeId{0}_2" value="2" onclick="changeAddItemButton({0},this.value)"><@s.m "cmsVoteTopic.type.mul"/></input><input type="radio" name="typeId{0}" id="typeId{0}_3" value="3" onclick="changeAddItemButton({0},this.value)"><@s.m "cmsVoteTopic.type.text"/></input>
&nbsp; <input class="del-button" type="button" value="<@s.m "global.delete"/>" onclick="$(this).parent().remove();"/>
<span id="voteItemMsg{0}" style="color: red;"></span>
<span><@s.m "cmsVoteTopic.items"/>&nbsp; <input id="addItem{0}" type="button" class="add_item" value="<@s.m "cmsVoteItem.addLines"/>" onclick="addLines({0});"/></span>
<input type="hidden" name="itemTitle" value="<@s.m "cmsVoteItem.splitchar"/>"/>
<div id="itemsContainer{0}"></div>
<input type="hidden" name="itemTitle" value="<@s.m "cmsVoteItem.splitchar"/>"/>
</div>
</textarea>

<textarea id="itemTpl" style="display:none;">
<div class="items">
<@s.m "cmsVoteItem.title"/>: <input type="text" id="{0}_{1}" name="itemTitle" style="width:300px"/>
&nbsp; <@s.m "cmsVoteItem.voteCount"/>: <input type="text" name="itemVoteCount" value="0" style="width:50px"/>
&nbsp; <@s.m "cmsVoteItem.priority"/>: <input type="text" name="itemPriority" value="{1}" style="width:30px"/>
&nbsp; <input class="del-button" type="button" value="<@s.m "global.delete"/>" onclick="$(this).parent().remove();"/>
</div>
</textarea>
<script type="text/javascript">
var tpl = $.format($("#itemTpl").val());
var index = 1;
function addLines(ind) {
	$("#itemsContainer"+ind).append(tpl(ind,index++));
}
var subtpl = $.format($("#subTopicTpl").val());
var subindex = 1;
function addSubTopic() {
	$("#subTopicContainer").append(subtpl(subindex++));
}
function changeAddItemButton(index,value){
	if(value==3){
			$("#addItem"+index).attr("disabled","disabled");
			$("#itemsContainer"+index).html("");
		}else{
			$("#addItem"+index).attr("disabled","");
			}
}
function checkVoteItem(){
	var subIndexId,subTypeName,subTypeObject,flag=true,voteItemMsgId;
	$("input[name='subtitle']").each(function(){
			subIndexId=$(this).attr("id").split("subtitle")[1];
			$("input[id^='typeId"+subIndexId+"']").each(function(i){
				subTypeObject=$(this);
				if(subTypeObject.prop("checked")&&subTypeObject.val()!=3){
					var i=0;
					$("input[id^='"+subIndexId+"']").each(function(){
							i++;
						});
					if(i==0){
							$("#voteItemMsg"+subIndexId).html("<@s.m 'cmsVoteItem.hasNoOne'/>");
							flag= false;
						}
				}
			});
		});
	return flag;
}
</script>

</body>
</html>